Elaboration of data output from SQL database
In [31]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from openpyxl import load_workbook
In [32]:
csv_folder='PV_higher_Results_csv'
In [33]:
#Import csv of endogenous variables for the whole users
cost_op_tot_all = pd.read_csv(f'{csv_folder}/cost_op_tot.csv',usecols=lambda column: column != 'id')
active_techs_all = pd.read_csv(f'{csv_folder}/active_techs.csv',usecols=lambda column: column != 'id')
cap_tot_all = pd.read_csv(f'{csv_folder}/cap_tot.csv',usecols=lambda column: column != 'id')
new_units_all = pd.read_csv(f'{csv_folder}/new_units.csv',usecols=lambda column: column != 'id')
cap_new_all = pd.read_csv(f'{csv_folder}/cap_new.csv',usecols=lambda column: column != 'id')
CO2_tot_all = pd.read_csv(f'{csv_folder}/CO2_tot.csv',usecols=lambda column: column != 'id')
CO2_act_all = pd.read_csv(f'{csv_folder}/CO2_act.csv',usecols=lambda column: column != 'id')
insulation_all = pd.read_csv(f'{csv_folder}/insulation.csv',usecols=lambda column: column != 'id')
X_all = pd.read_csv(f'{csv_folder}/X.csv',usecols=lambda column: column != 'id')
Xt_all = pd.read_csv(f'{csv_folder}/X_t.csv',usecols=lambda column: column != 'id')
Q_all = pd.read_csv(f'{csv_folder}/Q.csv',usecols=lambda column: column != 'id')
SOC_all = pd.read_csv(f'{csv_folder}/SOC.csv',usecols=lambda column: column != 'id')
# Importing exogenous data from data_input excel
excel_file = 'input_data/input_data.xlsx'
Y_all = pd.read_excel(excel_file, sheet_name='Y',usecols=lambda column: column != 'id')
cost_cap = pd.read_excel(excel_file, sheet_name='cost_cap',usecols=lambda column: column != 'id')
cost_period = pd.read_excel(excel_file, sheet_name='cost_period',usecols=lambda column: column != 'id')
cost_inv_all = pd.read_excel(excel_file, sheet_name='cost_inv',usecols=lambda column: column != 'id')
disc_frac_pd = pd.read_excel(excel_file, sheet_name='disc_frac',usecols=lambda column: column != 'id')
disc_frac=disc_frac_pd.at[0,'values']
TI_cost_all = pd.read_excel(excel_file, sheet_name='TI_cost',usecols=lambda column: column != 'id')
DPT = pd.read_excel(excel_file, sheet_name='days_per_type',usecols=lambda column: column != 'id')
u= pd.read_excel(excel_file, sheet_name='u',usecols=lambda column: column != 'id')
cf= pd.read_excel(excel_file, sheet_name='cf',usecols=lambda column: column != 'id')
cf = cf[cf['values'] != 1]
sf= pd.read_excel(excel_file, sheet_name='sf',usecols=lambda column: column != 'id')
sf = sf[sf['values'] != 0]
In [34]:
#Select the scenario to be analyzed
user='B'
#endogenous
cost_op_tot=cost_op_tot_all.loc[cost_op_tot_all['s_names'] == f'User{user}']
active_techs=active_techs_all.loc[active_techs_all['s_names'] == f'User{user}']
cap_tot=cap_tot_all.loc[cap_tot_all['s_names'] == f'User{user}']
new_units=new_units_all.loc[new_units_all['s_names'] == f'User{user}']
cap_new=cap_new_all.loc[cap_new_all['s_names'] == f'User{user}']
CO2_tot=CO2_tot_all.loc[CO2_tot_all['s_names'] == f'User{user}']
CO2_act=CO2_act_all.loc[CO2_act_all['s_names'] == f'User{user}']
insulation=insulation_all.loc[insulation_all['s_names'] == f'User{user}']
X=X_all.loc[X_all['s_names'] == f'User{user}']
Xt=Xt_all.loc[Xt_all['s_names'] == f'User{user}']
Q=Q_all.loc[Q_all['s_names'] == f'User{user}']
SOC=SOC_all.loc[SOC_all['s_names'] == f'User{user}']
#exogenous
Y=Y_all.loc[Y_all['s_names'] == f'User{user}']
cost_inv=cost_inv_all.loc[cost_inv_all['s_names'] == f'User{user}']
TI_cost=TI_cost_all.loc[TI_cost_all['s_names'] == f'User{user}']
for df in [cost_op_tot, active_techs, cap_tot, new_units, cap_new, CO2_tot, CO2_act, insulation, X, Xt, Q, SOC, Y, cost_inv, TI_cost]:
df.reset_index(drop=True, inplace=True)
In [35]:
activity_costs=sum(cost_op_tot['values'])
periodic_costs=sum((cost_period['values']+(cost_cap['values']*cap_tot['values']))*active_techs['values'])
bill_one_year=activity_costs+periodic_costs
discount=sum(disc_frac ** x for x in range(1, 11))
operation_costs_discounted=bill_one_year*discount
investment_costs=sum(cost_inv['values']*new_units['values'])
NPC=operation_costs_discounted+investment_costs
print('The NPC is over 10 years is: ', round(NPC,2),'€')
print('For each year the operative expenses are:', round(bill_one_year,2), '€')
print('The initial investment cost is:', round(investment_costs,2),'€')
The NPC is over 10 years is: 21828.63 € For each year the operative expenses are: 1407.86 € The initial investment cost is: 10120.0 €
In [36]:
investment_cost_breakdown=pd.DataFrame()
investment_cost_breakdown['t_names']=cost_inv['t_names']
investment_cost_breakdown['values']=cost_inv['values']*new_units['values']
investment_cost_breakdown['values']=investment_cost_breakdown['values'].round(2)
print('Technology expansion investment:\n', investment_cost_breakdown[investment_cost_breakdown['values']!=0])
Technology expansion investment:
t_names values
0 PV sys 1970.0
4 HP 3000.0
6 Storage HW 150.0
7 Radiators 4500.0
9 Induction stove 500.0
In [37]:
seasons = ['wi', 'mc', 'mw', 'su']
season_names = {'wi': 'Winter', 'mc': 'Mid-cold', 'mw': 'Mid-warm', 'su': 'Summer'}
In [38]:
#Isolate peak hour
peak_Y= Y[Y['th_names'] == 'peak']
Y=Y[Y['th_names'] != 'peak']
peak_Q= Q[Q['th_names'] == 'peak']
Q=Q[Q['th_names'] != 'peak']
peak_X=X[X['th_names'] == 'peak']
X=X[X['th_names'] != 'peak']
peak_Xt=Xt[Xt['th_names'] == 'peak']
Xt=Xt[Xt['th_names'] != 'peak']
SOC=SOC[SOC['th_names'] != 'peak']
DPT=DPT[DPT['days_names'] != 'peak']
In [39]:
#Temporal features
for db in [Y,Q,X,Xt,SOC]:
db.index=range(len(db))
db.loc[:,'season']=db['th_names'].str[4:6]
db['hour'] = db['th_names'].str[1:3].astype(int)
db['day'] = db['th_names'].str[-2:].astype(int)
db['time'] = (db['day'] - 1) * 24 + db['hour']
Costs and consumption
In [40]:
#EE consumption
cost_EE_period=cost_period.loc[cost_period['t_names']=='National Grid EE']['values'].values[0]+cost_cap.loc[cost_cap['t_names']=='National Grid EE']['values'].values[0]*cap_tot.loc[cap_tot['t_names']=='National Grid EE']['values'].values[0]
cost_EE=cost_op_tot.loc[cost_op_tot['a_names']=='National Grid import']['values'].values[0]+cost_op_tot.loc[cost_op_tot['a_names']=='National Grid export']['values'].values[0]+cost_EE_period
print('Yearly variable cost for electricity import:',round(cost_op_tot.loc[cost_op_tot['a_names']=='National Grid import']['values'].values[0],2),'€')
print('Yearly fixed cost for electricity import:',round(cost_EE_period,2),'€')
print('Yearly income for electricity export:',round(cost_op_tot.loc[cost_op_tot['a_names']=='National Grid export']['values'].values[0],2),'€')
print('Yearly net cost for electricity',round(cost_EE,2),'€')
Yearly variable cost for electricity import: 1061.79 € Yearly fixed cost for electricity import: 275.0 € Yearly income for electricity export: -8.93 € Yearly net cost for electricity 1327.86 €
In [41]:
#NG consumption
cost_NG_period=active_techs[active_techs['t_names']=='Gas National Grid']['values'].values[0]*cost_period.loc[cost_period['t_names']=='Gas National Grid']['values'].values[0]+cost_cap.loc[cost_cap['t_names']=='Gas National Grid']['values'].values[0]*cap_tot.loc[cap_tot['t_names']=='Gas National Grid']['values'].values[0]
cost_NG=cost_op_tot.loc[cost_op_tot['a_names']=='Natural Gas supply grid']['values'].values[0]+cost_NG_period
print('Yearly variable cost for natural gas import:',round(cost_op_tot.loc[cost_op_tot['a_names']=='Natural Gas supply grid']['values'].values[0],2),'€')
print('Yearly fixed cost for natural gas import:',round(cost_NG_period,2),'€')
print('Yearly total cost for natural gas',round(cost_NG,2),'€')
Yearly variable cost for natural gas import: 0.0 € Yearly fixed cost for natural gas import: 0.0 € Yearly total cost for natural gas 0.0 €
In [42]:
#CO2 emissions
print('First year CO2 emissions',round(CO2_tot,2),'kg')
CO2_breakdown=pd.DataFrame()
CO2_breakdown['values']=CO2_act['values'].round(2)
CO2_breakdown.index=CO2_act['a_names']
print('CO2 emissions:\n', CO2_breakdown[CO2_breakdown['values']!=0])
First year CO2 emissions s_names values
0 UserB 16424.41 kg
CO2 emissions:
values
a_names
National Grid import 1264.60
National Grid export -45.65
In [43]:
#Function to aggregate hourly data into daily data
def compute_daily(df):
#Group by day and season
df = df.groupby(['day', 'season']).agg(consumption=('values', 'sum')).reset_index()
#Fix the order
season_order = ['wi', 'mc', 'mw', 'su']
df['season'] = pd.Categorical(df['season'], categories=season_order, ordered=True)
df_sorted = df.sort_values(by=['season', 'day'])
df_sorted.index = range(len(df_sorted))
return df_sorted
In [44]:
#Yearly electricity consumption, production and supply
Q_EE=Q[Q['n_names']=='EE']
Q_EE_daily = compute_daily(Q_EE)
Q_EE_daily['consumption'] = Q_EE_daily['consumption']*DPT['values']
Q_EE_tot=sum(Q_EE_daily['consumption'])
print('Yearly consumption of electricity:',round(Q_EE_tot,2),'kWh')
X_EE_daily = compute_daily(X[X['a_names']=='National Grid import'])
X_EE_daily['consumption'] = X_EE_daily['consumption']*DPT['values']
print('Yearly import of electricity from National Grid:',round(sum(X_EE_daily['consumption']),2),'kWh')
print('Yearly auto-consumption',round(sum(Q_EE_daily['consumption'])-sum(X_EE_daily['consumption']),2),'kWh')
PV_prod=X[X['a_names']=='PV']
X_PV_daily = compute_daily(PV_prod)
X_PV_daily['consumption'] = X_PV_daily['consumption']*DPT['values']
print('Yearly PV production:',round(sum(X_PV_daily['consumption']),2),'kWh')
PV_sell=X[X['a_names']=='National Grid export']
X_sell_daily = compute_daily(PV_sell)
X_sell_daily['consumption'] = X_sell_daily['consumption']*DPT['values']
print('Yearly export of electricity to National Grid:',round(sum(X_sell_daily['consumption']),2),'kWh')
Yearly consumption of electricity: 6745.24 kWh Yearly import of electricity from National Grid: 5308.97 kWh Yearly auto-consumption 1436.28 kWh Yearly PV production: 1627.94 kWh Yearly export of electricity to National Grid: 191.67 kWh
GRAPHS
Electricity: use
In [45]:
EE_base=Y[Y['n_names']=='EE']
HP_prod_wi=X[X['a_names']=='HP heating winter']
HP_prod_su=X[X['a_names']=='HP heating summer']
HP_prod_wi.index=HP_prod_su.index=range(len(HP_prod_wi))
EE_HP_thermal=HP_prod_wi.copy()
EE_HP_thermal['values']=HP_prod_wi['values']+HP_prod_su['values']
EE_HP_wi_mc=EE_HP_thermal.loc[EE_HP_thermal['season'].isin(['wi', 'mc']), 'values']*u[(u['a_names'] == 'HP heating winter') & (u['n_names'] == 'EE')].values[0][2]
EE_HP_mw_su=EE_HP_thermal.loc[EE_HP_thermal['season'].isin(['su', 'mw']), 'values']*u[(u['a_names'] == 'HP heating summer') & (u['n_names'] == 'EE')].values[0][2]
EE_HP=EE_HP_thermal.copy()
EE_HP['values']=pd.concat([EE_HP_wi_mc,EE_HP_mw_su])
EE_AC=X[X['a_names']=='AC cooling']
EE_AC['values']=EE_AC['values']*u[(u['a_names'] == 'AC cooling') & (u['n_names'] == 'EE')].values[0][2]
EE_HP_cool=X[X['a_names']=='HP cooling']
EE_HP_cool['values']=EE_HP_cool['values']*u[(u['a_names'] == 'HP cooling') & (u['n_names'] == 'EE')].values[0][2]
EE_cook=X[X['a_names']=='Induction stove cooking']
EE_cook['values']=EE_cook['values']*u[(u['a_names'] == 'Induction stove cooking') & (u['n_names'] == 'EE')].values[0][2]
EE_base.index=EE_HP.index=EE_AC.index=EE_HP_cool.index=EE_cook.index=range(len(EE_base))
/var/folders/7_/h7wd3zm54kg_zntp92069r1h0000gn/T/ipykernel_3489/740339813.py:12: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy EE_AC['values']=EE_AC['values']*u[(u['a_names'] == 'AC cooling') & (u['n_names'] == 'EE')].values[0][2] /var/folders/7_/h7wd3zm54kg_zntp92069r1h0000gn/T/ipykernel_3489/740339813.py:14: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy EE_HP_cool['values']=EE_HP_cool['values']*u[(u['a_names'] == 'HP cooling') & (u['n_names'] == 'EE')].values[0][2] /var/folders/7_/h7wd3zm54kg_zntp92069r1h0000gn/T/ipykernel_3489/740339813.py:16: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy EE_cook['values']=EE_cook['values']*u[(u['a_names'] == 'Induction stove cooking') & (u['n_names'] == 'EE')].values[0][2]
In [46]:
#Electricity consumption
plt.figure(figsize=(35, 25))
Time=range(1,337)
Time_ind=pd.Index(range(1, 337))
ore_totali = 336
# Impostiamo le etichette per le ore del giorno (0-23) ripetute per 10 giorni
day_h = np.tile(np.arange(24), 14) # Ripeti le ore da 0 a 23 per 10 volte
# Creiamo un array per i giorni (Day 1, Day 2, ... Day 14)
day_names = np.repeat([f'Day {i+1}' for i in range(14)], 24)
# Uniamo i giorni e le ore per creare le etichette delle x
x_labels = [f'{day}\n{hour}:00' for day,hour in zip(day_names,day_h)]
# Impostiamo le etichette sull'asse delle x ogni 6 ore
for i, season in enumerate(seasons, 1):
Q_season = Q[(Q['season'] == season) & (Q['n_names'] == 'EE')]['values']
EE_base_season = EE_base[EE_base['season'] == season]['values']
EE_HP_season = EE_HP[EE_HP['season'] == season]['values']
EE_cook_season = EE_cook[EE_cook['season'] == season]['values']
EE_HP_cool_season = EE_HP_cool[EE_HP_cool['season'] == season]['values']
EE_AC_season = EE_AC[EE_AC['season'] == season]['values']
plt.subplot(4, 1, i)
plt.plot(Time, Q_season, color='black', linewidth=2, label='Total electricity consumption (Q)')
plt.fill_between(Time,0,EE_base_season, color='cornflowerblue', label='Appliances (Y)')
plt.fill_between(Time,EE_base_season,EE_base_season+EE_HP_season, color='orange', label='HP heating')
plt.fill_between(Time,EE_base_season+EE_HP_season,EE_base_season+EE_HP_season+EE_HP_cool_season, color='cyan', label='HP cooling')
plt.fill_between(Time,EE_base_season+EE_HP_season+EE_HP_cool_season,EE_base_season+EE_HP_season+EE_HP_cool_season+EE_AC_season, color='cyan', label='AC cooling')
plt.fill_between(Time,EE_base_season+EE_HP_season+EE_HP_cool_season+EE_AC_season,EE_base_season+EE_HP_season+EE_HP_cool_season+EE_AC_season+EE_cook_season, color='red', label='cooking')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('kWh')
plt.ylim(0,5)
plt.xlim(0,340)
plt.title(f'Electricity consumption in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Electricity: supply
In [47]:
Battery=X[X['a_names']=='Storing EE']
PV_prod.index = Q_EE.index = PV_sell.index =Battery.index = range(len(PV_prod))
Batt_charge=Battery.copy()
Batt_charge['values'] = Batt_charge['values'].apply(lambda x: 0 if x > 0 else x)
PV_consump=PV_prod.copy()
PV_consump['values']=PV_prod['values'].to_numpy()-PV_sell['values'].to_numpy()+Battery['values'].to_numpy()
PV_consump['values'] = PV_consump['values'].where(PV_prod['values']>0, 0)
PV_consump['values'] = PV_prod['values'].where((PV_prod['values']<Q_EE['values']) & (Battery['values']>=0), PV_consump['values'])
Batt_discharge=Battery.copy()
Batt_discharge['values'] = Batt_discharge['values'].to_numpy()-PV_sell['values'].to_numpy()
Batt_discharge['values'] = Batt_discharge['values'].apply(lambda x: 0 if x < 0 else x)
EE_grid=X[X['a_names']=='National Grid import']
In [48]:
#Electricity production
plt.figure(figsize=(35, 25))
Time=range(1,337)
Time_ind=pd.Index(range(1, 337))
for i, season in enumerate(seasons, 1):
Q_season = Q[(Q['season'] == season) & (Q['n_names'] == 'EE')]['values']
PV_prod_season = PV_prod[PV_prod['season'] == season]['values']
PV_consump_season = PV_consump[PV_consump['season'] == season]['values']
PV_consump_season.index=Time_ind
Batt_discharge_season = Batt_discharge[Batt_discharge['season'] == season]['values']
Batt_discharge_season.index=Time_ind
EE_grid_season = EE_grid[EE_grid['season'] == season]['values']
EE_grid_season.index=Time_ind
Batt_charge_season = Batt_charge[Batt_charge['season'] == season]['values']
Batt_charge_season.index=Time_ind
PV_sell_season=-PV_sell[PV_sell['season'] == season]['values']
PV_sell_season.index=Time_ind
plt.subplot(4, 1, i)
plt.plot(Time, Q_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.plot(Time, PV_prod_season, color='red', linewidth=1, label='PV production')
plt.fill_between(Time,0,PV_consump_season, color='orange', label='PV')
plt.fill_between(Time,PV_consump_season,PV_consump_season+Batt_discharge_season, color='green', label='Storage')
plt.fill_between(Time,PV_consump_season+Batt_discharge_season,PV_consump_season+Batt_discharge_season+EE_grid_season, color='blue', label='National Grid import')
#negative
plt.fill_between(Time,0,Batt_charge_season, color='greenyellow', label='Battery charging')
plt.fill_between(Time,Batt_charge_season,Batt_charge_season+PV_sell_season, color='pink', label='National Grid export')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('kWh')
plt.ylim(-3,5)
plt.xlim(0,340)
plt.title(f'Electricity supply in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
In [49]:
#Coverage of electrical needs
PV_consump_daily=PV_consump.groupby(['day', 'season']).agg(consumption=('values', 'sum')).reset_index()
PV_consump_daily['consumption'] = PV_consump_daily['consumption']*DPT['values']
import_NG=sum(X_EE_daily['consumption'])
consumo_PV=sum(PV_consump_daily['consumption'])
# Dati ipotetici (puoi modificarli con i tuoi valori)
labels = ['National Grid', 'Direct self-consumption (PV)', 'Indirect self-consumption (battery)']
sizes = [import_NG/Q_EE_tot, consumo_PV/Q_EE_tot,0]# (Q_EE_tot-import_NG-consumo_PV)/Q_EE_tot] # Percentuali di copertura
colors = ['#66b3ff','gold', '#99ff99'] # Colori personalizzati per ogni categoria
# Creazione del grafico a torta
plt.figure(figsize=(7, 7))
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90, colors=colors, wedgeprops={'edgecolor': 'black'})
# Assicurarsi che il grafico sia visualizzato come un cerchio
plt.axis('equal')
# Titolo del grafico
plt.title('Electrical needs coverage')
# Mostra il grafico
plt.show()
Hot water
In [50]:
HP_prod_wi=X[X['a_names']=='HP heating winter']
HP_prod_su=X[X['a_names']=='HP heating summer']
HP_prod_wi.index=HP_prod_su.index=range(len(HP_prod_wi))
HP_prod=HP_prod_wi.copy()
HP_prod['values']=HP_prod_wi['values']+HP_prod_su['values']
Boiler_prod=Xt[Xt['t_names']=='Gas Boiler']
HW_storage=X[X['a_names']=='Storing HW']
Q_HW=Q[Q['n_names']=='Hot water']
Q_HW.index = Boiler_prod.index=HW_storage.index =range(len(HP_prod))
stor_charge=HW_storage.copy()
stor_charge['values'] = stor_charge['values'].apply(lambda x: 0 if x > 0 else x)
stor_discharge=HW_storage.copy()
stor_discharge['values'] = stor_discharge['values'].apply(lambda x: 0 if x < 0 else x)
HP_use=HP_prod.copy()
HP_use['values']=HP_prod['values'].to_numpy()+stor_charge['values'].to_numpy()
HW_for_heating=Q[Q['n_names']=='Heat']
HW_for_heating['values']=HW_for_heating['values']*1.2
/var/folders/7_/h7wd3zm54kg_zntp92069r1h0000gn/T/ipykernel_3489/651615034.py:20: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy HW_for_heating['values']=HW_for_heating['values']*1.2
In [51]:
#Hot water production
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
Q_HW_season = Q[(Q['season'] == season) & (Q['n_names'] == 'Hot water')]['values']
HP_use_season = HP_use[HP_use['season'] == season]['values']
Boiler_prod_season = Boiler_prod[Boiler_prod['season'] == season]['values']
stor_charge_season = stor_charge[stor_charge['season'] == season]['values']
#PV_consump_season.index=Time_ind
stor_discharge_season = stor_discharge[stor_discharge['season'] == season]['values']
HW_heating_season = HW_for_heating[HW_for_heating['season'] == season]['values']
plt.subplot(4, 1, i)
plt.plot(Time, Q_HW_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.plot(Time, HW_heating_season, color='yellow', linewidth=1, label='Hot water for heating')
plt.fill_between(Time,0,HP_use_season, color='limegreen', label='Heat pump')
plt.fill_between(Time,HP_use_season,HP_use_season+Boiler_prod_season, color='salmon', label='Gas boiler')
plt.fill_between(Time,HP_use_season+Boiler_prod_season,HP_use_season+Boiler_prod_season+stor_discharge_season, color='teal', label='Storage')
#negative
plt.fill_between(Time,0,stor_charge_season, color='cyan', label='Storage charging')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('Thermal kWh')
plt.ylim(-5,10)
plt.xlim(0,340)
plt.title(f'Hot water consumption in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
In [52]:
#Zoom hot water production
plt.figure(figsize=(35, 15))
for i, season in enumerate(seasons, 1):
Q_HW_season = Q[(Q['season'] == season) & (Q['n_names'] == 'Hot water')]['values']
HP_use_season = HP_use[HP_use['season'] == season]['values']
Boiler_prod_season = Boiler_prod[Boiler_prod['season'] == season]['values']
stor_charge_season = stor_charge[stor_charge['season'] == season]['values']
#PV_consump_season.index=Time_ind
stor_discharge_season = stor_discharge[stor_discharge['season'] == season]['values']
HW_heating_season = HW_for_heating[HW_for_heating['season'] == season]['values']
plt.subplot(4, 1, i)
plt.plot(Time, Q_HW_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.plot(Time, HW_heating_season, color='yellow', linewidth=1, label='Hot water for heating')
plt.fill_between(Time,0,HP_use_season, color='limegreen', label='Heat pump')
plt.fill_between(Time,HP_use_season,HP_use_season+Boiler_prod_season, color='salmon', label='Gas boiler')
plt.fill_between(Time,HP_use_season+Boiler_prod_season,HP_use_season+Boiler_prod_season+stor_discharge_season, color='teal', label='Storage')
#negative
plt.fill_between(Time,0,stor_charge_season, color='cyan', label='Storage charging')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('Thermal kWh')
plt.ylim(-1,4)
plt.xlim(0,340)
plt.title(f'Hot water consumption in {season_names[season]}',fontsize=20)
plt.grid(True)
plt.tight_layout()
plt.show()
In [53]:
import os
model_dir_name = 'Sensitivity_EE_NG'
main_dir_path = 'tesi_camilla/casi_MarioU'
tot_path=main_dir_path+'/'+model_dir_name
results_csv_path = os.path.join(tot_path, 'Results_csv')
if not os.path.exists(results_csv_path):
os.makedirs(results_csv_path)
In [54]:
results_csv_path
Out[54]:
'tesi_camilla/casi_MarioU/Sensitivity_EE_NG/Results_csv'
Cooling
In [55]:
#Cooling supply
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
Q_cool_season = Q[(Q['season'] == season) & (Q['n_names'] == 'Cooling')]['values']
HP_cool_season = X[(X['season'] == season) & (X['a_names'] == 'HP cooling')]['values']
AC_cool_season = X[(X['season'] == season) & (X['a_names'] == 'AC cooling')]['values']
plt.subplot(4, 1, i)
plt.plot(Time, Q_cool_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.fill_between(Time,0,HP_cool_season, color='paleturquoise', label='Heat pump')
plt.fill_between(Time,0,AC_cool_season, color='slategrey', label='Air conditioning')
#negative
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('Thermal kWh')
plt.ylim(0,1)
plt.xlim(0,340)
plt.title(f'Cooling energy consumption in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Cooking
In [56]:
Gas_stove=X[X['a_names']=='Gas stove cooking']
Ind_stove=X[X['a_names']=='Induction stove cooking']
Gas_stove.index = Ind_stove.index =range(len(Gas_stove))
In [57]:
#Cooking supply
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
Q_cook_season = Q[(Q['season'] == season) & (Q['n_names'] == 'Cooking')]['values']
Gas_stove_season = Gas_stove[Gas_stove['season'] == season]['values']
Ind_stove_season = Ind_stove[Ind_stove['season'] == season]['values']
#PV_consump_season.index=Time_ind
plt.subplot(4, 1, i)
plt.plot(Time, Q_cook_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.fill_between(Time,0,Gas_stove_season, color='sandybrown', label='Gas stove')
plt.fill_between(Time,Gas_stove_season,Gas_stove_season+Ind_stove_season, color='darkviolet', label='Induction stove')
#negative
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('Thermal kWh')
plt.ylim(0,2)
plt.xlim(0,340)
plt.title(f'Cooking energy consumption in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
Natural Gas
In [58]:
#Natural gas consumption
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
Q_gas_season = Q[(Q['season'] == season) & (Q['n_names'] == 'Natural Gas')]['values']
Boiler_prod_season = Boiler_prod[Boiler_prod['season'] == season]['values']/10.94/0.95
Gas_stove_season = Gas_stove[Gas_stove['season'] == season]['values']/10.94/0.4
plt.subplot(4, 1, i)
plt.plot(Time, Q_gas_season, color='black', linewidth=2, label='Total Consumption (Q)')
plt.fill_between(Time,0,Boiler_prod_season, color='salmon', label='Boiler')
plt.fill_between(Time,Boiler_prod_season,Boiler_prod_season+Gas_stove_season, color='sandybrown', label='Stove')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('Nm3')
plt.ylim(0,0.5)
plt.xlim(0,340)
plt.title(f'Natural Gas consumption in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
In [59]:
#EE storage SOC
SOCEE=SOC[SOC['t_names']=='Storage EE']
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
Batt_charge_season = -Batt_charge[Batt_charge['season'] == season]['values']
Batt_discharge_season = -Batt_discharge[Batt_discharge['season'] == season]['values']
SOCEE_season = SOCEE[SOCEE['season'] == season]['values']
#PV_consump_season.index=Time_ind
plt.subplot(4, 1, i)
plt.plot(Time, SOCEE_season, color='black', linewidth=2, label='State of charge')
plt.bar(Time,Batt_charge_season, color='palegreen', label='Charging')
plt.bar(Time,Batt_discharge_season,color='orchid', label='Discharging')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('kWh')
plt.ylim(-3,6)
plt.xlim(0,340)
plt.title(f'Electrical storage in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
In [60]:
#HW storage SOC
SOCHW=SOC[SOC['t_names']=='Storage HW']
plt.figure(figsize=(35, 25))
for i, season in enumerate(seasons, 1):
stor_charge_season = -stor_charge[Batt_charge['season'] == season]['values']
stor_discharge_season = -stor_discharge[stor_discharge['season'] == season]['values']
SOCHW_season = SOCHW[SOCHW['season'] == season]['values']
#PV_consump_season.index=Time_ind
plt.subplot(4, 1, i)
plt.plot(Time, SOCHW_season, color='black', linewidth=2, label='State of charge')
plt.bar(Time,stor_charge_season, color='yellowgreen', label='Charging')
plt.bar(Time,stor_discharge_season,color='lightcoral', label='Discharging')
plt.axhline(y=11.9, color='red', linestyle='--', linewidth=1, label='SOC max')
plt.xticks(ticks=np.arange(0, 336, 8), labels=x_labels[::8], rotation=90)
plt.ylabel('kWh thermal')
plt.ylim(-8,14)
plt.xlim(0,340)
plt.title(f'Hot water storage in {season_names[season]}',fontsize=20)
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()